/*
 * @Author: mayijun
 * @Date: 2022-05-13 10:21:47
 * @LastEditors: mayijun
 * @LastEditTime: 2022-07-07 14:40:37
 */
// __MICRO_APP_ENVIRONMENT__和__MICRO_APP_PUBLIC_PATH__是由micro-app注入的全局变量
if (window.__MICRO_APP_ENVIRONMENT__) {
  // @ts-ignore
  __webpack_public_path__ = window.__MICRO_APP_PUBLIC_PATH__
}
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import installElement from '@/plugins/element-plus';
import ArcoVue from '@arco-design/web-vue';
import ArcoVueIcon from '@arco-design/web-vue/es/icon';

import { ElMessage } from 'element-plus/lib/index';
import { createPinia } from 'pinia';

import '@dangojs/vue-digitforce-theme/dist/css/index.css'
import '@/assets/arco-global.css'
import '@/assets/styles/index.scss';
import '@/assets/icons/iconfont.css';
import '@/assets/styles/common.scss';

// todo: 后面考虑自动引入样式
import '@dangojs/a-page-container/dist/css/index.css'
import '@dangojs/a-query-header/dist/css/index.css'
import '@dangojs/a-graph-card/dist/css/index.css'

import { store, key } from './store';
import { http } from '@/utils/http';
import { TOKEN_ERROR } from '@/utils/saber-http/authToken';
import { RESPONSE_ERROR } from '@/utils/saber-http/responseHandler';
import { drawerDrag } from './utils/dragDirective';
// import { setupElementPlus } from './plugins/elementPlus';

http.on(TOKEN_ERROR, () => {
  ElMessage.error('请重新登录');
});
http.on(RESPONSE_ERROR, (data) => {
  // 错误提示
  ElMessage.error(data.msg);
});

if (
  process.env.VUE_APP_PUBLISHNAME === 'DEV' ||
  'TEST' === process.env.VUE_APP_PUBLISHNAME
) {
  require('./mock');
}

const app = createApp(App);
app.use(store, key);
app.use(router);
app.use(createPinia());
// setupElementPlus(app);
installElement(app);
//注册自定义指令
drawerDrag(app);
app.use(ArcoVue, {});
app.use(ArcoVueIcon);
// 全局异常处理器
app.config.errorHandler = (err, vm, info) => {
  console.log('[全局异常]', err, vm, info)
}
app.mount('#app, .is-component');
